#ifndef TOUCHCONV_H
#define TOUCHCONV_H

#include <QMainWindow>
#include <QString>
#include <QProcess>
#include <QTime>
#include <QQueue>

#include "FFmpeg.h"

class QTreeWidget;
class QComboBox;
class QPushButton;
class QLineEdit;
class QCheckBox;
class QProgressBar;
class QLabel;
class QTime;
class QCloseEvent;

class BatchList;

class TouchConv: public QMainWindow
{
	Q_OBJECT
	
public:
	TouchConv(QWidget *parent = NULL);

protected:
	void closeEvent(QCloseEvent *);

protected slots:
	void startConvert();
	void finishConvert();
	
	void abort();
	
	void changeOutputDirectory();

private:
	// auto remove from list
	QCheckBox *autoRemoveFinishedItem;
	
/*
	// stop when current converting finished
	QCheckBox *stopAfterCurrentConvert;
*/

	// convert profile
	QComboBox *profile;
	QComboBox *outputSuffix;
	QStringList profileArgs;
	QStringList converter;
	QStringList profileSuffix;
	
	// batch list
	BatchList *batchList;
	QPushButton *removeItemButton, *clearButton;
	QPushButton *upButton, *downButton;
	
	// output setting
	QLineEdit *outputDirectory;
	QPushButton *changeOutputDirectoryButton;
	
	// operations
	QPushButton *convertButton;
	QPushButton *abortButton;
	
	// current information
	QProgressBar *currentProgressBar;
	QLabel *currentFile;
	QLabel *timeElapsed;
	QLabel *estimatedTotalTime;
	QLabel *timeRemain;
	
	// total progress
	QProgressBar *totalProgressBar;
	QLabel *progress;
	
	// FFmpeg
	FFmpeg ffmpeg;
	
	// item count
	int total;
	
	// current file path
	QString currentFilePath;
	
	// Queue
	QQueue<QString> queue;
	
	// current status
	QLabel *status;
	QTime totalTime;
	QLabel *totalElapsedTime;
	
	// provided for convinience
	QString outputPath(const QString &) const;
	static QString pathToFilename(const QString &);
	
	// load setting profiles
	void loadSettingProfiles(const QString &dir = "profiles");
	
	// set suffix
	void setSuffixForSelectedProfile(int);
	
	// setup
	void setupStatusBar();
	
private slots:
	void processFinished(int, QProcess::ExitStatus);
	
	// enable/disable user input
	void lockInterface();
	void unlockInterface();
	
	// update progress by signal from FFmpeg
	void updateProgress(int);
	
	// start convert
	void convert();
};

#endif	// TOUCHCONV_H
